type CoreModule = typeof import('../../wasm-core/pkg/func_draw_core');

let coreModulePromise: Promise<CoreModule> | null = null;

async function loadCoreModule(): Promise<CoreModule> {
  if (!coreModulePromise) {
    coreModulePromise = import('../../wasm-core/pkg/func_draw_core').then(async (module) => {
      if (typeof module.default === 'function') {
        await module.default();
      }
      return module;
    });
  }
  return coreModulePromise;
}

export async function evaluateExpression(expression: string, x: number, y: number): Promise<number> {
  const module = await loadCoreModule();
  return module.evaluate_expression(expression, x, y);
}
